<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0,user-scalable=no,minimal-ui">
    <title>桔子❀</title>
    <link rel="icon" href="./../images/favico.ico">
    <!--element-ui的样式-->
    <link rel="stylesheet" href="../../backend/plugins/element-ui/index.css"/>
    <!-- 引入样式  -->
    <link rel="stylesheet" href="../styles/index.css"/>
    <!--引入vant样式-->
    <link rel="stylesheet" href="../styles/vant.min.css"/>
    <!--本页面内容的样式-->
    <link rel="stylesheet" href="./../styles/user-edit.css"/>
</head>
<body>
<div id="user-edit" class="app">
    <div id="divHead">
        <div id="divTitle">
            <i class="el-icon-arrow-left" @click="goBack"></i>修改信息
        </div>
        <div id="divBody">
            <div id="userAvatar">
                <img src="../images/userAvatar/pic1.jpeg"/>
                <el-button class="editBtn" type="button">更改头像</el-button>
            </div>
            <div id="userInfo">
                <div class="infoBody">
                    <span class="cacc">账号：</span><el-input class="acc" v-model="userInfo.name">{{userInfo.name}}</el-input>
                </div>
                <div class="infoBody">
                    <span class="cname">昵称：</span><el-input class="name" v-model="userInfo.account" readonly>{{userInfo.account}}</el-input>
                </div>
                <div class="infoBody">
                    <span class="csex">
                        性别：
                    </span>
                    <el-radio-group class="sex" v-model="userInfo.sex">
                        <el-radio :label="'-1'">男</el-radio>
                        <el-radio :label="'0'">保密</el-radio>
                        <el-radio :label="'1'">女</el-radio>
                    </el-radio-group>
                </div>
                <div>
                    <el-button class="saveBtn" @click="editUserInfo">保存</el-button>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 开发环境版本，包含了有帮助的命令行警告 -->
<script src="../../backend/plugins/vue/vue.js"></script>
<!-- 引入组件库 -->
<script src="../../backend/plugins/element-ui/index.js"></script>
<!-- 引入vant组件 -->
<script src="./../js/vant.min.js"></script>
<!--不同屏幕尺寸根字体设置-->
<script src="./../js/base.js"></script>
<!-- 引入axios -->
<script src="../../backend/plugins/axios/axios.min.js"></script>
<script src="./../js/request.js"></script>
<script src="./../api/user.js"></script>
<script>
    new Vue({
        el: "#user-edit",
        data() {
            return {
                msgFlag: false,
                userInfo: {
                    id: '',
                    //用户名字
                    name: '',
                    //登录账号
                    account: '',
                    //性别
                    sex: '',
                    //头像地址
                    avatar: '',
                    //用户状态
                    status: ''
                }
            }
        },
        computed: {
            genderImage() {
                if (this.userInfo.sex === "1") {
                    return './../images/female.png';
                } else if (this.userInfo.sex === "0") {
                    return './../images/secrecy.png';
                } else {
                    return './../images/male.png';
                }
            }
        },
        created() {
            this.getUserInfo()
        },
        mounted() {},
        methods: {
            async getUserInfo() {
                const res = await userInfoApi();
                if (res.code === 1) {
                    this.userInfo = res.data
                }
            },
            async editUserInfo() {
                const res = await userEditApi(this.userInfo)
                if (res.code === 1) {
                    this.$notify({type: 'success', message: "修改成功"});
                } else {
                    this.$notify({type: 'warning', message: "修改失败"});
                    this.goBack()
                }
            },
            goBack() {
                history.go(-1)
            }
        }
    })
</script>
</body>
</html>